package com.zzedu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzedu.domain.ZzClasses;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 班级管理Mapper接口
 *
 * @author Mr.Wang
 * @date 2025-01-29
 */
public interface ZzClassesMapper extends BaseMapper<ZzClasses> {
    @Select("<script>" +
            "SELECT school_id , COUNT(*) AS clzz_count " +
            "FROM zz_classes " +
            "WHERE deleted = 0 " +
            "<if test='schoolIds != null and schoolIds.size() > 0'> " +
            "AND school_id IN " +
            "<foreach item='id' collection='schoolIds' open='(' separator=',' close=')'> " +
            "#{id} " +
            "</foreach> " +
            "</if> " +
            "GROUP BY school_id " +
            "</script>")
    List<Map<String, Object>> countClzzsBySchool(@Param("schoolIds") List<Long> schoolIds);

    @Select({
            "<script>",
            "SELECT ",
            "b.stu_id AS stuId,",
            "GROUP_CONCAT(a.`name`) as clzzName,",
            "GROUP_CONCAT(c.`name`) as teacherName",
            "FROM zz_classes a ",
            "left join zz_stu_classes_r b on a.id=b.class_id",
            "left join zz_teacher c on c.id=a.teacher_id ",
            "WHERE a.deleted=0 and b.deleted=0 ",
            "<if test='stuIdList != null and stuIdList.size() > 0'>",
            "AND b.stu_id IN",
            "<foreach item='id' collection='stuIdList' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</if>",
            "GROUP BY  b.stu_id ",
            "</script>"
    })
    List<Map<String, Object>> selectStudentClzzInfo(@Param("stuIdList") List<Long> stuIdList);
}
